import request from "../utils/request";
// import axios from "axios"
// const request = axios.create({
//     baseURL: '/dev-api', // 设置默认的 API 地址，url = baseURL + url（使用proxy代理时此处可不写）
//     timeout: 5000,						  // 设置请求超时时间
// })
/**
 * 资料柜
 */
// 查询资料柜名称编号
export function getBoxName() {
  return request({
    url: "/book-cabinet/selectName",
    method: "get",
  });
}
export function getLogin() {
  return request({
    url: "/dev-api/getInfo",
    method: "get",
  });
}

// 查询资料柜的节
export function getBoxJie() {
  return request({
    url: "/book-cabinet-drawer/selectJoint",
    method: "get",
  });
}

// 查询资料柜的层
export function getBoxCeng() {
  return request({
    url: "/book-cabinet-drawer/selectStorey",
    method: "get",
  });
}

// 查询资料柜列表
export function getBoxList(params: any) {
  return request({
    url: "/book-cabinet/selectPage",
    method: "get",
    params,
  });
}

// 新增资料库
export function addBoxLibrary(data: any) {
  return request({
    url: "/book-cabinet",
    method: "post",
    data,
  });
}

// 编辑资料柜
export function editBox(data: any) {
  return request({
    url: "/book-cabinet",
    method: "put",
    data,
  });
}

// 删除资料柜
export function deleteBox(bookInfo: any) {
  return request({
    url: "/book-cabinet/" + bookInfo,
    method: "delete",
  });
}

// 获取书柜列表
export function getBoxDetail(params: any) {
  return request({
    url: "/book-cabinet-drawer/selectPage",
    method: "get",
    params,
  });
}

//
// 增加容量
export function addBoxDrawer(data: any) {
  return request({
    url: "/book-cabinet-drawer",
    method: "put",
    data,
  });
}

/**
 * 资料
 */

// 查询资料表列表
export function getBooks(params: any) {
  return request({
    url: "/book-info/selectPage",
    method: "get",
    params: params,
  });
}

// 新增资料表
export function addBooks(data: any) {
  return request({
    url: "/book-info",
    method: "post",
    data: data,
  });
}

// 编辑资料表
export function editBooks(data: any) {
  return request({
    url: "/book-info",
    method: "put",
    data: data,
  });
}

// 删除资料表
export function deleteBooks(bookInfoIds: any) {
  return request({
    url: "/book-info/" + bookInfoIds,
    method: "delete",
  });
}

// 导出资料表
export function exportBooks() {
  return request({
    url: "/book-info/export",
    method: "post",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    responseType: "blob",
  });
}

// 导入资料表
export function importBooks(file: any) {
  return request({
    url: "/book-info/importData",
    method: "post",
    data: file,
    headers: { "Content-Type": "multipart/form-data" },
  });
}

// 下载模板
export function downloadTemplate() {
  return request({
    url: "/book-info/importTemplate",
    method: "post",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    responseType: "blob",
  });
}

// 绑定条形码
export function bindCode(data: any) {
  return request({
    url: "/book-binding",
    method: "post",
    data: data,
  });
}

/**
 * 在库
 */

// 全部在库列表（分页）
export function getInStockList(params: any) {
  return request({
    url: "/book-binding/selectPage",
    method: "get",
    params,
  });
}

// 根据ids查询在库信息
export function getInStockByIds(bookBindingIds: any) {
  return request({
    url: "/book-binding/selectByIds/" + bookBindingIds,
    method: "get",
  });
}

// 借阅申请
export function borrowApply(data: any) {
  return request({
    url: "/book-receive",
    method: "post",
    data,
  });
}
export function speechRecognize(data: any) {
  return request({
    url: "/speech/recognize",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  // const formData = new FormData();
  //     formData.append('audio', data);
  // request.post('/speech/recognize', formData, {
  //   headers: {
  //     'Content-Type': 'multipart/form-data'
  //   }
  // })
  // .then(response => {
  //   // 处理响应
  //   console.log(response.data);
  // })
  // .catch(error => {
  //   // 处理错误
  //   console.error(error);
  // });
}

// 上传单据
export function uploadBill(data: any) {
  return request({
    url: "/book-binding/uploadDocument",
    method: "post",
    data,
    headers: { "Content-Type": "multipart/form-data" },
  });
}

/**
 * 已贴码
 */
// 查询已贴码列表
export function getBindCodeList(params: any) {
  return request({
    url: "/book-info/selectPageBind",
    method: "get",
    params,
  });
}

// 资料入库
export function addInStock(data: any) {
  return request({
    url: "/book-binding/updateStoreyStatus",
    method: "post",
    data,
  });
}

// 推荐入库柜子抽屉
export function recommendCabinet(params: any) {
  return request({
    url: "/book-cabinet-drawer/selectRecommendCabinet",
    method: "get",
    params,
  });
}

// 判断绑定码
export function judgeCode(params: any) {
  return request({
    url: "/book-binding/selectBarCodeIsBind",
    method: "get",
    params,
  });
}

// 全部入库
export function allInStock(data: any) {
  return request({
    url: "/book-binding/updateBookBindingResidue",
    method: "post",
    data,
  });
}

/**
 * 资料请领
 */

// 资料申请列表（分页）
export function getApplyList(params: any) {
  return request({
    url: "/book-receive/selectPage",
    method: "get",
    params,
  });
}

// 资料申请详情
export function getApplyDetail(id: any) {
  return request({
    url: "/book-receive/" + id,
    method: "get",
  });
}

// 判断绑定码是否存在
export function judgeCodeExist(params: any) {
  return request({
    url: "/book-receive/getBarCodeExists",
    method: "get",
    params,
  });
}

// 确认请领
export function confirmReceive(data: any) {
  return request({
    url: "/book-receive/confirmReceive",
    method: "post",
    data,
  });
}

// 操作日志

// 查询操作流水记录
export function getLogList(params: any) {
  return request({
    url: "/book-log/selectPage",
    method: "get",
    params,
  });
}

// 推荐归还柜子
export function recommendReturnCabinet(params: any) {
  return request({
    url: "/book-receive/getRecommendCabinet",
    method: "get",
    params,
  });
}

// 归还子列表
export function getReturnList(receiveId: any) {
  return request({
    url: "/book-receive/returnList/" + receiveId,
    method: "get",
  });
}

// 确认归还
export function confirmReturn(data: any) {
  return request({
    url: "/book-receive/screen/confirmReturn",
    method: "post",
    data,
  });
}

// 查询资料柜级联数据
export function getCabinetList() {
  return request({
    url: "/book-cabinet/selectCascade",
    method: "get",
  });
}

// 确认回收
export function confirmRecycle(data: any) {
  return request({
    url: "/book-receive/confirmRecover",
    method: "post",
    data,
  });
}
// 确认全部归还
export function confirmAllReturn(data: any) {
  return request({
    url: "/book-receive/confirmAllReturn",
    method: "post",
    data,
  });
}

/**
 * 大屏新接口
 */

// 通过条形码查询资料信息入库用
export function getBookInfoByCode(code: any) {
  return request({
    url: "/book-info/selectBookInfo/" + code,
    method: "get",
  });
}

// 通过条形码查询资料信息归还用
export function getBookInfoByCodeReturn(code: any) {
  return request({
    url: "/book-receive/getByBarCode/" + code,
    method: "get",
  });
}

// 查询资料柜信息
export function getCabinetInfo(bookCabinetId: any) {
  return request({
    url: "/book-cabinet/getBookCabinet/" + bookCabinetId,
    method: "get",
  });
}

/**
 * 大屏
 */
//  新增请领申请
export function addApply(data: any) {
  return request({
    url: "/book-receive/screen",
    method: "post",
    data,
  });
}

// 资料库借阅前十
export function getTopTen() {
  return request({
    url: "/book-stat/bookReceiveNumber",
    method: "get",
  });
}

// 资料库入库前十
export function getTopTenIn() {
  return request({
    url: "/book-stat/bookStoreyNumber",
    method: "get",
  });
}

// 查询统计
export function getStat() {
  return request({
    url: "/book-stat/bookTotal",
    method: "get",
  });
}

// 资料在库前十
export function getTopTenInStore() {
  return request({
    url: "/book-stat/bookWarehouseNumber",
    method: "get",
  });
}

// 资料库每月借阅情况统计
export function getMonthStat(year: any) {
  return request({
    url: `/book-stat/bookReceive/${year}`,
    method: "get",
  });
}

// 资料库每月归还情况统计
export function getMonthReturnStat(year: any) {
  return request({
    url: `/book-stat/bookReturn/${year}`,
    method: "get",
  });
}

// 资料库每月资料领用率
export function getMonthRateStat(year: any) {
  return request({
    url: `/book-stat/bookReceiveRate/${year}`,
    method: "get",
  });
}

// 资料库每月资料归还率
export function getMonthReturnRateStat(year: any) {
  return request({
    url: `/book-stat/bookReturnRate/${year}`,
    method: "get",
  });
}

/**
 * 查询记录
 */
// 查询图书库存记录
export function getBookRecord(params: any) {
  return request({
    url: "/book-stat/selectBookWarehousePage",
    method: "get",
    params,
  });
}

// 查询图书入库记录
export function getBookInRecord(params: any) {
  return request({
    url: "/book-stat/selectBookLogStoreyPage",
    method: "get",
    params,
  });
}

// 查询图书请领记录
export function getBookApplyRecord(params: any) {
  return request({
    url: "/book-stat/selectBookLogReceivePage",
    method: "get",
    params,
  });
}

// 查询图书归还记录
export function getBookReturnRecord(params: any) {
  return request({
    url: "/book-stat/selectBookLogReturnPage",
    method: "get",
    params,
  });
}

/**
 * sockt认证
 */
export function getSocketToken() {
  return request({
    url: "/hik-event/test",
    method: "post",
  });
}
export function getSocket() {
  return request({
    url: "hik-event/testToken",
    method: "post",
  });
}

// 查询图书库存记录
export function getBookStorey(params: any) {
  return request({
    url: "/book-stat/selectBookWarehousePage",
    method: "get",
    params,
  });
}

// 查询检查记录
export function getCheckRecord(params: any) {
  return request({
    url: "/book-inspect-log/selectPage",
    method: "get",
    params,
  });
}

// 请领存放位置列表（分页）
export function getApplyPosition(params: any) {
  return request({
    url: "/book-binding/screen/selectStorageLocationPage",
    method: "get",
    params,
  });
}

// 查询检查次数
export function getCheckLog() {
  return request({
    url: "/book-inspect-log/getInspectNumber",
    method: "get",
  });
}

/**
 * 开柜
 */

export function definiteOpening(dataParam: any) {
  // return this.lineOpen()
  let val = dataParam;
  let parame = [
    {
      quNo: val.region,
      colNo: val.arrange,
      leNo: val.joint,
      divNo: val.storey,
      zyNo: val.side,
    },
  ];
  var url =
    "http://" +
    val.ipAddress +
    ":9000/MjjWebApi/OpenByTask?JsonData=" +
    JSON.stringify(parame);
  var data = {
    urlString: url,
  };
  return request({
    url: "/book-receive/openByTask",
    method: "post",
    data,
  });
  // $.ajax({
  //   dataType: "json",
  //   type: "post",
  //   url: `http://` + val.ipAddress + `:9000/MjjWebApi/OpenByTask?JsonData=` + JSON
  //     .stringify(parame),
  //   //  data: parame,
  //   processData: false,
  //   contentType: false,
  //   success: (data) => {
  //     console.log("开柜成功返回：{}"+data);
  //   }
  // });
}
export function addCheckLog(data: any) {
  return request({
    url: "/book-inspect-log",
    method: "post",
    data,
  });
}
